<template>
  <div class="jeecg-basic-table jeecg-basic-table-form-container">
    <!--引用表格-->
    <BasicTable @register="registerTable" :expandedRowKeys="expandedRowKeys" @expand="handleExpand" :rowSelection="rowSelection">
      <!-- 内嵌table区域 begin -->
      <template #tableTitle>
        <a-button type="primary" preIcon="ant-design:export-outlined" @click="onExportXls"> 导出</a-button>
        <a-button type="primary" preIcon="ant-design:printer-outlined" @click="batchPrint"> 批量打印</a-button>
      </template>
      <!--操作栏-->
      <template #action="{ record }">
        <TableAction :actions="getTableAction(record)" />
      </template>
      <template #fileSlot="{ text }">
        <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
        <a-button v-else :ghost="true" type="primary" preIcon="ant-design:download-outlined" size="small"
          @click="downloadFile(text)">下载</a-button>
      </template>
    </BasicTable>
    <!-- 表单区域 -->
    <!-- <LabSampleModal @register="registerModal" @success="handleSuccess"></LabSampleModal> -->
    <!-- 条形码区域 -->
    <LabSampleBarModal @register="registeBarModal"> </LabSampleBarModal>
     <!-- 二维码弹窗 -->
     <LabSampleQrModal @register="registeQrModal"> </LabSampleQrModal>
     <!-- 批量打印二维码 -->
     <BatchPrintQrModal @register="registeBatchPrintQrModal"> </BatchPrintQrModal>

    <!-- 样品处置 -->
    <!-- <LabSampleHandleModal @register="registerHModal" @success="handleSuccess"></LabSampleHandleModal> -->
  </div>
</template>

<script lang="ts" setup>
import { ref } from 'vue';
import { BasicTable, TableAction } from '/@/components/Table';
import { useModal } from '/@/components/Modal';
import { useListPage } from '/@/hooks/system/useListPage';
// import LabSampleModal from './components/LabSampleModal.vue'
// import LabItemsSubTable from './subTables/LabItemsSubTable.vue';
import { samColumns, searchFormSchema } from './LabSample.data';
import { entrutSamList, getSamExportXls } from './LabSample.api';
import LabSampleBarModal from './LabSampleBar.vue';
// import LabSampleHandleModal from '../sample_handle/components/LabSampleHandleForm.vue';
import LabSampleQrModal from '/@/views/lab/wentrust/subTables/LabSampleQr.vue';
import BatchPrintQrModal from './subTables/BatchPrintQrModal.vue';
import { useMessage } from '/@/hooks/web/useMessage';

import QRcode from "qrcode";
import { QrCode, QrCodeActionType } from '/@/components/Qrcode/index';
import printJS from 'print-js';


// 展开key
const expandedRowKeys = ref<any[]>([]);
// const [registerModal, { openModal: sOpenModal }] = useModal();
//弹窗注册
const [registeBarModal, { openModal: bOpenModal }] = useModal();
//注册二维码弹窗
const [registeQrModal, { openModal: openModalQr }] = useModal();
//注册批量二维码
const [registeBatchPrintQrModal, { openModal: openModalBatchPrint }] = useModal();
//弹窗注册
// const [registerHModal, { openModal: hOpenModal}] = useModal();
const { createMessage } = useMessage();
//注册table数据
const { tableContext, onExportXls } = useListPage({
  tableProps: {
    title: '样品信息',
    api: entrutSamList,
    columns:samColumns,
    canResize: false,
    showIndexColumn: true,
    formConfig: {
      schemas: searchFormSchema,
      autoSubmitOnEnter: true,
      showAdvancedButton: true,
      fieldMapToNumber: [
      ],
      fieldMapToTime: [
      ],
    },
    actionColumn: {
      width: 120,
      fixed: 'right'
    },
  },
  exportConfig: {
    name: "样品信息",
    url: getSamExportXls,
  },
})


const [registerTable, { reload,getSelectRows }, { rowSelection, selectedRowKeys }] = tableContext
/**
  * 展开事件
  * */
function handleExpand(expanded, record) {
  expandedRowKeys.value = [];
  if (expanded === true) {
    expandedRowKeys.value.push(record.id)
  }
}

//打开条形码弹窗
function openBarCode(record) {
  bOpenModal(true, record);//record 将数据传到条形模块中
}


/**
 * 退回
 */
// function sampleBack(record: Recordable) {
//   sOpenModal(true, {
//     record
//   });
// }

/**
 * 成功回调
 */
function handleSuccess() {
  (selectedRowKeys.value = []) && reload();
}

//批量打印
function batchPrint() {
  console.log('数据',getSelectRows());
  if(getSelectRows().length>0){
    openModalBatchPrint(true, getSelectRows());//record 将数据传到条形模块中
  }else{
    createMessage.warning('请选择数据!');
  }
}


/**
 * 打开样品处置
 */
// function handleOpen(){
//   hOpenModal(true, {
//     isUpdate: false,
//     disabled: false,
//     showFooter: true,
//   });
// }

function openQrCode(record){
  openModalQr(true, record);//record 将数据传到条形模块中
}

/**
   * 操作栏
   */
function getTableAction(record) {
  // if (record.samStatus == '备样') {
  //   return [
  //     {
  //       label: '条形码',
  //       onClick: openBarCode.bind(null, record),
  //     },
  //     {
  //       label: '二维码',
  //       onClick: openQrCode.bind(null, record),
  //     }
  //   ]
  // } else {
  //   return [
  //     {
  //       label: '回收',
  //       onClick: sampleBack.bind(null, record),
  //     },
  //     {
  //       label: '条形码',
  //       onClick: openBarCode.bind(null, record),
  //     },{
  //       label: '二维码',
  //       onClick: openQrCode.bind(null, record),
  //     }
  //   ]
  // }

  return [
      {
        label: '条形码',
        onClick: openBarCode.bind(null, record),
      },
      {
        label: '二维码',
        onClick: openQrCode.bind(null, record),
      }
    ]


}



</script>

<style scoped></style>